/*
**************************************************************************************
*Myriad Engine                                                                       *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
package leola.frontend;

import leola.ast.ASTNode;
import leola.frontend.events.ParserSummaryEvent;
import leola.frontend.parsers.ProgramParser;

/**
 * @author Tony
 *
 */
public class LeolaParser extends Parser {

	/**
	 * @param scanner
	 */
	public LeolaParser(Scanner scanner					 
					 , ExceptionHandler exceptionHandler) {
		super(scanner, exceptionHandler);
	}
	
	/**
	 * Copy constructor
	 * @param parser
	 */
	public LeolaParser(LeolaParser parser) {
		this(parser.getScanner(), parser.getExceptionHandler());
	}

	/* (non-Javadoc)
	 * @see leola.frontend.Parser#getErrorCount()
	 */
	@Override
	public int getErrorCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	
	
	/* (non-Javadoc)
	 * @see leola.frontend.Parser#parse()
	 */
	@Override
	public ASTNode parse() throws Exception {
        long startTime = System.currentTimeMillis();
        ASTNode program = null;
        try {
            Token token = nextToken();

            // Parse a program.
            ProgramParser programParser = new ProgramParser(this);            
            program = programParser.parse(token);
            
            // Send the parser summary message.
            float elapsedTime = (System.currentTimeMillis() - startTime) / 1000.0f;
            getEventDispatcher().sendNow( new ParserSummaryEvent(this, token.getLineNumber(),getErrorCount(), elapsedTime) );
            
        }
        catch (java.io.IOException ex) {
            this.getExceptionHandler().onException(ex);
        }
        
        return program;
	}

}
